import request from "@/utils/request";

/**
 * 分组列表
 */
export const groupList = () => {
  return request({
    url: "/crm/build/list",
    method: "get"
  });
};

/**
 * 新增分组
 * @param { object } params
 * @param { string } params.groupName -分组名称
 */
export const addGroup = params => {
  return request({
    url: "/crm/build/addGroup",
    method: "post",
    params
  });
};

/**
 * 更新分组
 * @param { string } id -分组id
 * @param { object } params
 * @param { string } params.groupName -分组名称
 */
export const updateGroup = (id, params) => {
  return request({
    url: `/crm/build/updateGroup/${id}`,
    method: "put",
    params
  });
};

/**
 * 排序
 */
export const sortGroup = data => {
  return request({
    url: "/crm/build/sort",
    method: "put",
    data
  });
};

/**
 * 删除分组
 * @param { string } id -分组id
 */
export const delGroup = id => {
  return request({
    url: `/crm/build/deleteGroup/${id}`,
    method: "delete"
  });
};

/**
 * 分组详情
 */
export const groupDetail = id => {
  return request({
    url: `/crm/build/detail/${id}`,
    method: "get"
  });
};

/**
 * 获取分组列表字段
 */
export const allConditionField = () => {
  return request({
    url: "/crm/build/selectField",
    method: "get"
  });
};

/**
 * 获取所有列表字段
 */
export const allFieldList = () => {
  return request({
    url: "/crm/build/allField",
    method: "get"
  });
};

/**
 * 保存分组设置
 * @param { string } id -分组id
 * @param { GroupSaveParams } data -分组设置
 */
export const saveGroupSetting = (id, data) => {
  return request({
    url: `/crm/build/saveConfig/${id}`,
    method: "put",
    data
  });
};
